from datetime import datetime
from sqlalchemy import Column, BigInteger, Enum, Text, DateTime, text, ForeignKey, Integer, Index, String
from core.database import Base



class CallTaskCustomers(Base):
    __tablename__ = 'call_task_customers'
    # 主键
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment='主键ID')
    # 轮呼状态
    call_status = Column(Enum('pending','dialing','connected','ended','completed','failed'), nullable=False, default='pending', comment='轮呼状态')
    # 轮呼结果
    call_result = Column(Text, nullable=True, comment='轮呼结果')
    # 呼叫时间
    call_time = Column(DateTime, nullable=True, comment='轮呼时间')
    # 接通时间
    connected_time = Column(DateTime, nullable=True, comment='接通时间')
    # 结束时间
    completed_time = Column(DateTime, nullable=True, comment='结束时间')
    # 通话时间
    call_duration = Column(Integer, nullable=True, comment='通话时长')
    # 创建时间
    created_at = Column(DateTime, default=datetime.now, server_default=text('CURRENT_TIMESTAMP'), comment='创建时间')

    task_id = Column(BigInteger, nullable=False, comment='任务ID')

    customer_id = Column(String(255), nullable=False, comment='客户ID')

    __table_args__ = (
        Index('idx_customer_id', 'customer_id'),
        Index('idx_task_id', 'task_id'),
        Index('idx_call_status', 'call_status')
    )